<?php
class Votes_model extends CI_Model {
  function __construct()
  {
    // Call the Model constructor
    parent::__construct();
  }

  function insert_entry($target_id, $user_id)
  {
    $this->db->insert('votes', array('uid' => $target_id, 'voter_id' => $user_id));
    if ($this->db->affected_rows() == '1')
    {
      return TRUE;
    }

    return FALSE;
  }

  function get_entry($cond) {
    $query = $this->db->get_where('votes', $cond, 1);
    return $query->row();
  }

  function get_avatar_votes($aid) {
    return $result = $this->db->select('COUNT(id) as avatar_votes')
    ->from('votes')
    ->where(array('uid' => $aid))
    ->limit(1)
    ->get()->row(0)->avatar_votes;
  }
}